package com.wolfden.drugserver;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.plugin.Plugin;

public class EventManager implements Listener {

	private Plugin plugin;

	public EventManager(Plugin plugin) {
		this.plugin = plugin;
		plugin.getServer().getPluginManager().registerEvents(this, plugin);
	}

	@EventHandler
	public void onLogin(PlayerLoginEvent event) {
		plugin.getServer().broadcastMessage(
				event.getPlayer().getDisplayName()
						+ "is now playing on the server.");
		if (Constants.moneyMap.getBalance(event.getPlayer().getName()) == -1) {
			Constants.moneyMap.addAccount(event.getPlayer().getName(), 100);
			plugin.getLogger().info("new account created for " + event.getPlayer().getName());
		} else {
			plugin.getLogger().info(event.getPlayer().getName() + " has " + Constants.moneyMap.getBalance(event.getPlayer().getName()));
		}
	}
}
